package org.example.base.impl;




import org.example.base.TemplateBase;
import org.example.entity.BasicInfoEntity;
import org.example.entity.TableEntity;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * Service 模板
 *
 */
public class TemplateService implements TemplateBase {

    /**
     * 基本信息
     */
    private BasicInfoEntity base;

    /**
     * 表格信息
     */
    private TableEntity table;

    /**
     * 带参构造器
     *
     * @param base  基本信息
     * @param table 表信息
     */
    public TemplateService(BasicInfoEntity base, TableEntity table) {
        this.base = base;
        this.table = table;
    }

    public String getTemplateName() {
        return base.getService().getTemplateName();
    }

    public File getFile() {
        File path = new File(base.getService().getFilePath());
        //判断文件目录是否存在
        if (!path.exists()) {
            path.mkdirs();
        }

        String fileName = base.getService().getFilePath() + File.separator + base.getService().getClassName() + JAVA_FILE_SUFFIX;
        File file = new File(fileName);

        return file;
    }

    public Map<String, Object> getDataMap() {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("base", base);
        dataMap.put("table", table);
        return dataMap;
    }
}
